/**
 * Description: pause函数的使用
 * File: signal.c |Time: 2021-04-07 10:34
 */

#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>


int main(int argc, char *argv[])
{
    pid_t pid = fork();

    if (pid == 0) {
#if 0
        printf("son start.\n");
        int i = 5;
        while(i--){
            printf("son working.\n");
            sleep(1);
        }
        printf("son end.\n");
#endif
        sleep(1);
        kill(getppid(), SIGUSR1);
    } else {

        

        printf("wait for signal:\n");
        int signal = pause();
        printf("catch signal: %d\n", signal);
        if (-1 == signal)
        {
            printf("pause error.\n");
        }


        while (1) {
            printf("I am father.\n");
            sleep(1);
        }
    }

    
    return 0;

}

